#include "Background.hh"

Background::Background(Window &win) : _Window(win)
{
    //ctor
}

Background::~Background()
{
    //dtor
}

void    Background::Initialize(sf::Sprite &background,sf::Vector2f &speed)
{
    this->_Speed = speed;
    this->_Sprite1 = background;
    this->_Sprite2 = background;
    this->_Sprite1.Resize(this->_Window.GetWidth(), this->_Window.GetHeight());
    this->_Sprite2.Resize(this->_Window.GetWidth(), this->_Window.GetHeight());
    int i = this->_Sprite2.GetSize().x;
    this->_Sprite2.Move(sf::Vector2f(i, 0));
    this->_Timer = 0.0f;
}

void    Background::LoadContent(void)
{

}

void    Background::UnloadContent(void)
{

}

void    Background::Draw(Time ElapsedTime)
{
    this->_Window.Draw(this->_Sprite1);
    this->_Window.Draw(this->_Sprite2);
}

void    Background::Update(Time ElapsedTime)
{
    this->_Timer += ElapsedTime;
    if (this->_Timer <= 0.001f)
        return;
    this->_Timer = 0.0f;
    if (this->_Sprite1.GetSize().x <= -this->_Sprite1.GetPosition().x)
        this->_Sprite1.Move(sf::Vector2f(this->_Sprite1.GetSize().x * 2, 0));

    if (this->_Sprite2.GetSize().x <= -this->_Sprite2.GetPosition().x)
        this->_Sprite2.Move(sf::Vector2f(this->_Sprite2.GetSize().x * 2, 0));

    this->_Sprite1.Move(this->_Speed);
    this->_Sprite2.Move(this->_Speed);
}
